import { IPSAppCounterRef } from '../../app/control/ipsapp-counter-ref';
import { PSAjaxControlImpl } from '../psajax-control-impl';
import { IPSLayout } from '../layout/ipslayout';
import { IPSAppMenu } from './ipsapp-menu';
import { IPSAppMenuItem } from './ipsapp-menu-item';

export class PSAppMenuImpl extends PSAjaxControlImpl implements IPSAppMenu {
  get appMenuStyle(): 'ICONVIEW' | 'LISTVIEW' | 'SWIPERVIEW' | 'LISTVIEW2' | 'LISTVIEW3' | 'LISTVIEW4' | 'EXTVIEW1' | 'EXTVIEW2' | 'EXTVIEW3' | 'EXTVIEW4' | 'EXTVIEW5' | 'USER' | 'USER2' {
    return this.M.appMenuStyle;
  }

  get codeName(): string {
    return this.M.codeName;
  }

  get layoutMode(): 'TABLE' | 'TABLE_12COL' | 'TABLE_24COL' | 'FLEX' | 'BORDER' | 'ABSOLUTE' {
    return this.M.layoutMode;
  }

  protected psappcounterref: IPSAppCounterRef | null = null;

  getPSAppCounterRef(): IPSAppCounterRef | null {
    if (this.psappcounterref != null) return this.psappcounterref;
    const value = this.M.getPSAppCounterRef;
    if (value == null) {
      return null;
    }
    this.psappcounterref = this.getPSModel4('app.control.IPSAppCounterRef', value, 'getPSAppCounterRef') as IPSAppCounterRef;
    return this.psappcounterref;
  }

  get psAppCounterRef(): IPSAppCounterRef | null {
    return this.getPSAppCounterRef();
  }

  getPSAppCounterRefMust(): IPSAppCounterRef {
    const value = this.getPSAppCounterRef();
    if (value == null) {
      throw new Error('未指定应用计数器引用');
    }
    return value;
  }

  protected psappmenuitems: IPSAppMenuItem[] | null = null;

  getPSAppMenuItems(): IPSAppMenuItem[] | null {
    if (this.psappmenuitems == null) {
      this.psappmenuitems = this.fillChildListModel(this.M.getPSAppMenuItems, 'control.menu.IPSAppMenuItem') as IPSAppMenuItem[];
    }
    return this.psappmenuitems;
  }

  get psAppMenuItems(): IPSAppMenuItem[] | null {
    return this.getPSAppMenuItems();
  }

  findPSAppMenuItem(objKey: any): IPSAppMenuItem | null {
    return this.getPSModel5('control.menu.IPSAppMenuItem', this.getPSAppMenuItems(), objKey) as IPSAppMenuItem;
  }

  protected pslayout: IPSLayout | null = null;

  getPSLayout(): IPSLayout | null {
    if (this.pslayout != null) return this.pslayout;
    const value = this.M.getPSLayout;
    if (value == null) {
      return null;
    }
    this.pslayout = this.getPSModel4('control.layout.IPSLayout', value, 'getPSLayout') as IPSLayout;
    return this.pslayout;
  }

  get psLayout(): IPSLayout | null {
    return this.getPSLayout();
  }

  getPSLayoutMust(): IPSLayout {
    const value = this.getPSLayout();
    if (value == null) {
      throw new Error('未指定看板布局');
    }
    return value;
  }

  get enableCustomize(): boolean {
    return this.M.enableCustomize;
  }

  get cls(): string {
    return 'PSAppMenuImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'app.IPSApplicationObject' || cls == 'app.appmenu.IPSAppMenuModel' || cls == 'control.layout.IPSLayoutContainer' || cls == 'control.menu.IPSAppMenu') return true;
    return super.instanceof(cls);
  }
}
